﻿using Blazor.CoffeeTalesApi.Entity;

namespace Blazor.Model.Entity;

public class DeviceIdKey: IWhitelistKey
{
    private readonly string _deviceId;

    public DeviceIdKey(string deviceId)
    {
        _deviceId = deviceId;
    }
    
    public DeviceIdKey(ReadOnlySpan<char> deviceId)
    {
        _deviceId = deviceId.ToString();
    }

    public bool Equals(IWhitelistKey? other)
    {
        if (other is null)
        {
            return false;
        }

        return other is DeviceIdKey key && Equals(key);
    }

    public string GetJsonRepresent()
    {
        return $"device_id:{_deviceId}";
    }

    public override string ToString()
    {
        return _deviceId;
    }

    protected bool Equals(DeviceIdKey other)
    {
        return _deviceId == other._deviceId;
    }

    public override bool Equals(object? obj)
    {
        if (obj is null) return false;
        if (ReferenceEquals(this, obj)) return true;
        if (obj.GetType() != GetType()) return false;
        return Equals((DeviceIdKey)obj);
    }

    public override int GetHashCode()
    {
        return _deviceId.GetHashCode();
    }
}